home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / _fixsfsi.s < prev    next >
Text File  |  1992-05-17  |  1KB  |  72 lines

  1. |
  2. |  single float to long conversion routine
  3. |
  4. | Andreas Schwab (schwab@ls5.informatik.uni-dortmund.de)
  5. |  mostly copied from _fixdfsi.cpp
  6. |  (error check removed because no checking possible)
  7.  
  8.  
  9.  
  10.     .text
  11.     .even
  12.  
  13.  
  14.  
  15. BIAS4    =    0x7F-1
  16.  
  17.     .globl    ___fixsfsi
  18. ___fixsfsi:
  19.     movel    sp@(4),d0    | get number
  20.     movel    d2,sp@-        | save register
  21.     movel    d0,d1
  22.     swap    d1        | extract exp
  23.     movew    d1,d2        | extract sign
  24.     lsrw    #7,d1
  25.     andw    #0xff,d1    | kill sign bit
  26.  
  27.     andl    #0x7fffff,d0    | remove exponent from mantissa
  28.     orl    #0x800000,d0    | restore implied leading "1"
  29.  
  30.     cmpw    #BIAS4,d1    | check exponent
  31.     blt    zero        | strictly factional, no integer part ?
  32.     cmpw    #BIAS4+32,d1    | is it too big to fit in a 32-bit integer ?
  33.     bgt    toobig
  34.  
  35.     subw    #BIAS4+24,d1    | adjust exponent
  36.     bgt    2f        | shift up
  37.     beq    7f        | no shift (never too big)
  38.  
  39. 1:    negw    d1
  40.     lsrl    d1,d0        | shift down to align radix point;
  41.                 | extra bits fall off the end (no rounding)
  42.     bra    7f        | never too big
  43.  
  44. 2:    lsll    d1,d0        | shift up to align radix point
  45.  
  46. 3:    cmpl    #0x80000000,d0    | -2147483648 is a nasty evil special case
  47.     bne    6f
  48.     tstw    d2        | this had better be -2^31 and not 2^31
  49.     bpl    toobig
  50.     bra    8f
  51. 6:    tstl    d0        | sign bit set ? (i.e. too big)
  52.     bmi    toobig
  53. 7:
  54.     tstw    d2        | is it negative ?
  55.     bpl    8f
  56.     negl    d0        | negate
  57. 8:
  58.     movel    sp@+,d2
  59.     rts
  60.  
  61. zero:
  62.     clrl    d0        | make the whole thing zero
  63.     bra    8b
  64.  
  65. toobig:
  66.     movel    #0x7fffffff,d0    | ugh. Should cause a trap here.
  67.     bra    8b
  68.  
  69.  
  70.  
  71.  
  72.